<template>
  <div>
    <button @click="dispatchFn">向A广播</button>
  </div>
</template>

<script>
import Emitter from '../mixins/emitter.js';
import { findComponentUpward, findBrothersComponents } from '@/utils/assist'
export default {
  name: 'componentB',
  mixins: [Emitter],
  created() {
    const comA = findComponentUpward(this, 'componentA');
    if (comA) {
      console.log(comA.name);
    }
    this.$on('on-message', this.showMessage);
  },
  mounted() {
    const comsB = findBrothersComponents(this, 'componentB');
    console.log('comsB', comsB);
  },
  methods: {
    showMessage(text) {
      window.alert(text);
    },
    dispatchFn() {
      this.dispatch('componentA', 'on-messageA', 'Hello AVue.js');
    }
  }
}
</script>

<style lang="less" scoped>
</style>